package al48rotate;

public class Rotate48 {

    public static void rotate(int[][] matrix) {

        int row = matrix.length;
        int col = matrix[0].length;
        int tempCol = 0;
        int temp ;
        for (int i = 0; i < row; i++) {
            for (int j = tempCol; j < col; j++) {
                temp = matrix[i][j];
                matrix[i][j] = matrix[j][i];
                matrix[j][i] = temp;
            }
            tempCol++;
        }

        for (int i = 0; i < row; i++) {
            for (int j = 0; j < col/2; j++) {
                temp = matrix[i][j];
                matrix[i][j] = matrix[i][col-j-1];
                matrix[i][col-j-1] = temp;
            }
        }

    }



    public static void main(String[] args) {
/*        int[][] nums = {{1,1,1},
                        {1,0,1},
                        {1,1,1}};*/
        /*int[][] nums = {{-4,-2147483648,6,-7,0},
                {-8,6,-8,-6,0},
                {2147483647,2,-9,-6,-10}};*/

        int[][] nums = {{1,2,3},
                        {4,5,6},
                        {7,8,9}};
        /*
           {{7,4,1},
            {6,5,2},
            {9,6,3}};*/
        /*        int[][] nums = {{0,1}};*/
        rotate(nums);

        // 使用循环遍历输出二维数组
        for (int i = 0; i < nums.length; i++) {
            for (int j = 0; j < nums[i].length; j++) {
                System.out.print(nums[i][j] + " ");
            }
            System.out.println(); // 换行
        }
    }

}
